<template>
  <button @click="$emit('click')" :class="type" class="base-button" type="button">
    <slot>按钮</slot>
  </button>
</template>

<script>
export default {
  name: 'BaseButton',
  props: {
    type: {
      type: String,
      default: 'default',
      validator(v) {
        // 只能是 danger/success/default三者中的某一个
        return ['danger', 'success', 'default', 'primary', 'warning'].includes(v)
      },
    },
  },
}
</script>

<style scoped lang="less">
.base-button {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  border-width: 1px;
  border-style: solid;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
  padding: 5px 10px;
  font-size: 14px;
  border-radius: 4px;
  // success风格样式
  &.success {
    background-color: #fff;
    color: #67c23a;
    border-color: #67c23a;
    &:hover {
      background-color: #67c23a;
      color: white;
    }
  }
  // 默认风格样式
  &.default {
    background-color: #ffffff;
    color: #909399;
    border-color: #909399;
    &:hover {
      background-color: #909399;
      color: #fff;
    }
  }
  // 危险风格样式
  &.danger {
    background-color: #ffffff;
    color: #f56c6c;
    border-color: #f56c6c;
    &:hover {
      background-color: #f56c6c;
      color: #fff;
    }
  }
  &.primary {
    background-color: #ffffff;
    color: #409eff;
    border-color: #409eff;
    &:hover {
      background-color: #409eff;
      color: #fff;
    }
  }
  &.warning {
    background-color: #ffffff;
    color: #e6a23c;
    border-color: #e6a23c;
    &:hover {
      background-color: #e6a23c;
      color: #fff;
    }
  }
  // 相邻的按钮添加间隙
  & + .base-button {
    margin-left: 5px;
  }
}
</style>
